package com.lanchetech.dao;

import com.lanchetech.bean.request.CountByTimeReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.UserDetailResp;
import com.lanchetech.bean.vo.LongCountByDateVO;
import com.lanchetech.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Mapper
public interface UserMapper {
    int deleteByPrimaryKey(Long id);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    User findOneByUsername(@Param("username") String username);

    User findOneByUsernameAndStatus(@Param("username") String username, @Param("status") Integer status);

    User findOneByOpenid(@Param("openid") String openid);

    int updateUsernameById(@Param("updatedUsername") String updatedUsername, @Param("id") Long id);

    int updateNicknameById(@Param("updatedNickname") String updatedNickname, @Param("id") Long id);

    List<User> findAllPage(PageReq req);

    UserDetailResp findOneById(@Param("id") Long id);

    int updatePointById(@Param("updatedPoint") BigDecimal updatedPoint, @Param("id") Long id);

    Long countAll();

    Long countByTimeRange(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    int updateAvatarById(@Param("updatedAvatar") String updatedAvatar, @Param("id") Long id);

    List<User> findAllByUserIds(@Param("userIds") List<Long> userIds);

    List<User> findAllByUsernames(@Param("usernames") List<String> usernames);

    int updateCoinById(@Param("updatedCoin") BigDecimal updatedCoin, @Param("id") Long id);

    User findOneByNicknameLike(@Param("likeNickname") String likeNickname);

    int changePointById(@Param("diffPoint") BigDecimal diffPoint, @Param("id") Long id);

    int changeCoinById(@Param("diffCoin") BigDecimal diffCoin, @Param("id") Long id);

    int updateExpAndLevelById(@Param("updatedExp") Integer updatedExp, @Param("updatedLevel") Integer updatedLevel, @Param("id") Long id);

    int updateExpById(@Param("updatedExp") Integer updatedExp, @Param("id") Long id);

    int updateLevelById(@Param("updatedLevel") Integer updatedLevel, @Param("id") Long id);

    int updateStatusById(@Param("updatedStatus") Integer updatedStatus, @Param("id") Long id);

    Long findOneNormalById(@Param("id") Long id);

    int updateCardPointById(@Param("updatedCardPoint") BigDecimal updatedCardPoint, @Param("id") Long id);

    int updateAdPointById(@Param("updatedAdPoint") BigDecimal updatedAdPoint, @Param("id") Long id);

    int updateShopIdById(@Param("updatedShopId") Long updatedShopId, @Param("id") Long id);

    int updatePayPasswordById(@Param("updatedPayPassword") String updatedPayPassword, @Param("id") Long id);

    List<User> findAll();

    int updateRegisterIdById(@Param("registerId") String registerId, @Param("id") Long id);

    List<User> findAllByShopId(Long shopId);

    List<User> findAllByShopIdAndRegisterIdIsNotNull(Long shopId);

    List<User> findAllByShopIdsAndRegistIdIsNotNull(@Param("list") List<Long> shopIds);

    List<User> findAllByShopIdIsNotNullAndRegisterId();

    int updateStaffTypeById(@Param("staffType") Byte staffType, @Param("id") Long id);

    @Select("<script>" +
            "select DATE_FORMAT(created_at, '%Y-%m-%d') day,\n" +
            "       COUNT(id) total\n" +
            "from user\n" +
            "<if test=\"startTime != null and startTime != '' and endTime != null and endTime != ''\">where created_at between #{startTime} and #{endTime}\n </if>" +
            "group by day\n" +
            "limit 30" +
            "</script>")
    List<LongCountByDateVO> getRegisterUserCount(CountByTimeReq req);

    int changePointAndCardPoint(@Param("amount") BigDecimal amount, @Param("id") Long id);

    List<Long> findIdByNicknameLike(@Param("nickname") String nickname);

    List<Long> findIdByNicknameLikeAndLevel(@Param("nickname") String nickname,@Param("level") Integer level);

    Long countByUsernameLike(@Param("username") String username);

    List<Long> findIdByUsernameLike(@Param("username") String username);

    BigDecimal getCoin(Long id);

    void updateCardPoint(BigDecimal newCardPoint, Long id);
}